package eleme.openapi.sdk.api.service;

import eleme.openapi.sdk.api.annotation.Service;
import eleme.openapi.sdk.api.base.BaseNopService;
import eleme.openapi.sdk.api.exception.ServiceException;
import eleme.openapi.sdk.oauth.response.Token;
import eleme.openapi.sdk.config.Config;
import eleme.openapi.sdk.api.entity.market.*;
import eleme.openapi.sdk.api.enumeration.market.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
 * 服务市场服务
 */
@Service("eleme.market")
public class MarketService extends BaseNopService {
    public MarketService(Config config,Token token) {
        super(config, token, MarketService.class);
    }

    /**
     * 同步某一段时间内的服务市场消息
     *
     * @param start 开始时间
     * @param end 结束时间
     * @param offset 消息偏移量
     * @param limit 查询消息数
     * @return 服务市场订单
     * @throws ServiceException 服务异常
     */
    public MarketMessages syncMarketMessages(Date start, Date end, int offset, int limit) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("start", start);
        params.put("end", end);
        params.put("offset", offset);
        params.put("limit", limit);
        return call("eleme.market.syncMarketMessages", params);
    }

    /**
     * 创建内购项目订单
     *
     * @param request 创建订单请求信息
     * @return 订单编号
     * @throws ServiceException 服务异常
     */
    public String createOrder(OrderRequest request) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("request", request);
        return call("eleme.market.createOrder", params);
    }

    /**
     * 查询服务市场订单
     *
     * @param orderNo 服务市场订单编号
     * @return 订单详情
     * @throws ServiceException 服务异常
     */
    public OrderQueryResponse queryOrder(String orderNo) throws ServiceException {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("orderNo", orderNo);
        return call("eleme.market.queryOrder", params);
    }
}
